package com.yixing.tech.entity.controller;

import com.yixing.tech.common.base.BaseControl;
import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.common.base.Rs;
import com.yixing.tech.entity.service.IObjModelService;
import com.yixing.tech.common.vo.s5.ActionVO;
import com.yixing.tech.common.vo.s5.EventVO;
import com.yixing.tech.common.vo.s5.ObjModelVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yixing tech
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/model")
public class ObjModelController extends BaseControl {

    @Resource
    IObjModelService objModelService;

    @PostMapping("/get")
    public Rs<Object> getOne(@RequestBody ObjModelVO vo) throws BusinessException {
        vo =objModelService.queryByCondition(vo);
        return Rs.ok(vo);
    }

    @PostMapping("/add")
    public Rs<Object> add(@RequestBody ObjModelVO vo) throws BusinessException {
        vo.setProductId("nbwatermeter");
        vo.setTenantId("6204cb763da841718ddd1cf8");
        objModelService.add(vo);
        return Rs.ok();
    }

    @PostMapping("/action/add")
    public Rs<Object> addAction(@RequestBody ActionVO vo) throws BusinessException {
        objModelService.insertAction(vo);
        return Rs.ok();
    }
    @PostMapping("/event/add")
    public Rs<Object> addEvent(@RequestBody EventVO vo) throws BusinessException {
        objModelService.insertEvent(vo);
        return Rs.ok();
    }

    @GetMapping("/product/{productId}/actions")
    public Rs<Object> getActions(@PathVariable String productId) throws BusinessException {
        List<ActionVO> actions = objModelService.getActions(productId);
        return Rs.ok(actions);
    }
    @GetMapping("/product/{productId}/action")
    public Rs<Object> getAction(@PathVariable String productId,String funCode,String code) throws BusinessException {
        ActionVO action = objModelService.getAction(productId, funCode, code);
        return Rs.ok(action);
    }




}
